package com.zxk.version4.consumer;

import com.zxk.version4.core.RpcRequest;
import com.zxk.version4.core.RpcResponse;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * @author： 朱小康
 * @create： 2024/5/29 18:21
 */
public class SimpleRpcClient implements RpcClient{

    private String host;
    private int port;



    @Override
    public RpcResponse sendRequest(RpcRequest request) {

        try {
            Socket socket = new Socket(host, port);

            ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());

            System.out.println(request);
            objectOutputStream.writeObject(request);
            objectOutputStream.flush();

            RpcResponse response = (RpcResponse) objectInputStream.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }


        return null;
    }
}
